package cn.itcast.service.system.impl;

import cn.itcast.common.utils.Encrypt;
import cn.itcast.dao.system.UserDao;
import cn.itcast.domain.system.User;
import cn.itcast.service.system.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class UserServiceImpl implements UserService {

	@Autowired
	private UserDao userDao;

	//分页
	public PageInfo findAll(int page, int size, String companyId) {
		PageHelper.startPage(page,size);
		List<User> list = userDao.findAll(companyId);
		return new PageInfo(list);
	}

	@Override
	public User findById(String userId) {
		return userDao.findById(userId);
	}

	@Override
	public void delete(String userId) {
		userDao.delete(userId);
	}

	@Override
	public void save(User user) {
		//设置id
		user.setId(UUID.randomUUID().toString());
		userDao.save(user);
	}

	@Override
	public void update(User user) {
		userDao.update(user);
	}

	//根据邮箱查询用户
	public User findByEmail(String email) {
		return userDao.findByEmail(email);
	}

    @Override
    public String findCityById(String id) {
        return userDao.findCityById(id);
    }

	@Override
	public User findByOpenId(String openid) {
		return userDao.findByOpenId(openid);
	}

    @Override
    public User findByCompanyIdAndDegree(String companyId, int degree) {
		return userDao.findByCompanyIdAndDegree(companyId,degree);
    }

	@Override
	public void updatePassword(User user) {
		userDao.updatePassword(user);
	}

	@Override
	public List<User> findByBirthDay(String date) {
		return userDao.findByBirthDay(date);
	}
}
